home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3666 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: expression must have class type
  5. Date: Thu, 25 Jan 1996 12:55:01 GMT
  6. Organization: Netcom
  7. Message-ID: <31077d2b.55409600@nntp.ix.netcom.com>
  8. References: <4e74k2$jku@NNTP.MsState.Edu>
  9. NNTP-Posting-Host: ix-dc7-21.ix.netcom.com
  10. X-NETCOM-Date: Thu Jan 25  4:54:53 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. topher@ERC.MsState.Edu (John Christopher Lakey) wrote:
  14.  
  15. > I get this error when I use a constructor with no args,
  16. > but not when I use one with an arguement.
  17. > Here's a code example:
  18. > class NexRadMessage {
  19. > public:
  20. >   NexRadMessage();
  21. >   //NexRadMessage(char *filename);
  22. >   ~NexRadMessage();
  23. >   ...
  24. > };
  25. > NexRadMessage::NexRadMessage()
  26. > {
  27. >   _messageCode = -1;
  28. > }
  29. > NexRadMessage::NexRadMessage(char *filename)
  30. > {
  31. >   if (filename)
  32. >     loadMessage(filename);
  33. >   else _messageCode = -1;
  34. > }
  35. > main(int argc,char **argv)
  36. > {
  37. >   //NexRadMessage message("argv[1]");  // tested and works (so far).
  38. >   NexRadMessage message();
  39. >   message.loadMessage(argv[1]);
  40. > }
  41. > "nexrad.C", line 106: error(3240): expression must have class type
  42. >     message.loadMessage(argv[1]);
  43. >     ^
  44. > This work fine if I use the first declaration, but not the second.
  45. > Any clue what I've done wrong?   I'm using IRIX 5.3 (NCC) C++
  46.  
  47. The problem is that the declaration
  48.  
  49.     NexRadMessage message();
  50.  
  51. isn't doing what you want.  It is not defining message as an instance
  52. of NexRadMessage -- it's declarring it as a function returning
  53. NexRadMessage.  Change this to
  54.  
  55.     NexRadMessage message;
  56.  
  57.  
  58. Michael M Rubenstein
  59.